from django import forms
from .models import User
from django.contrib import messages


class RegisterForm(forms.ModelForm):
    password_2 = forms.CharField(max_length=16)
    
    def clean(self):
        clean_data = super(RegisterForm, self).clean()
        password = clean_data.get('password')
        password_2 = clean_data.get('password_2')
        if password != password_2:
            raise forms.ValidationError("两次密码输入不一致！")
        else:
            return clean_data

    class Meta:
        model = User
        fields = ['username', 'password', 'email']


class LoginForm(forms.ModelForm):

    class Meta:
        model = User
        fields = ['email', 'password']


class TransferForm(forms.ModelForm):

    money = forms.FloatField()

    class Meta:
        model = User
        fields = ['email']


